'
' DotNetNukeŽ - http://www.dotnetnuke.com
' Copyright (c) 2002-2006
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
'
Imports System
Imports System.Web
Imports System.Web.Compilation
Imports System.Data
Imports System.Reflection
Imports System.Collections.Generic
Imports DotNetNuke
Imports DotNetNuke.Security.Roles
Imports DotNetNuke.Security.Membership
Namespace DotNetNuke.Modules.IWeb

    Public Class IWebCoreData

#Region "PortalRoles"

        Public Shared Function PortalRoles(ByVal PortalId As Integer) As List(Of IWebRoleInfo)
            Dim colPortalRoles As New List(Of IWebRoleInfo)
            Dim RoleController As RoleController = New RoleController
            Dim arrArraylist As ArrayList
            arrArraylist = RoleController.GetPortalRoles(PortalId)

            Dim tmpIWebRoleInfo As New IWebRoleInfo()
            tmpIWebRoleInfo.RoleName = "Host"
            colPortalRoles.Add(tmpIWebRoleInfo)

            For Each objRoleInfo As RoleInfo In arrArraylist
                Dim objIWebRoleInfo As New IWebRoleInfo()
                objIWebRoleInfo.RoleName = objRoleInfo.RoleName
                colPortalRoles.Add(objIWebRoleInfo)
            Next

            Return colPortalRoles
        End Function

#End Region

#Region "PortalList"

        Public Shared Function PortalList() As List(Of IWebPortalInfo)
            Dim colPortalList As New List(Of IWebPortalInfo)
            Dim colPortalController As New PortalController()
            Dim colPortalInfo As PortalInfo
            Dim arrArraylist As ArrayList
            arrArraylist = colPortalController.GetPortals()

            For Each colPortalInfo In arrArraylist
                Dim objIWebPortalInfo As New IWebPortalInfo()
                objIWebPortalInfo.PortalID = colPortalInfo.PortalID
                objIWebPortalInfo.PotalName = "Portal: [" & CStr(colPortalInfo.PortalID) & "] " & colPortalInfo.PortalName
                colPortalList.Add(objIWebPortalInfo)
            Next
            Return colPortalList
        End Function

#End Region

#Region "GetMethodsInDatabase"

        Public Shared Function GetMethodsInDatabase(ByVal PorlalID As Integer) As List(Of IWEBMethodInfo)
            Dim IWEBMethodInfoList As New List(Of IWEBMethodInfo)

            Dim mySqlString As New StringBuilder()
            mySqlString.Append("SELECT PortalID, MethodName, MethodDescription, SecuritySetting, CompanyName, ApplicationName, FirstGrouping, SecondGrouping ")
            mySqlString.Append("FROM {databaseOwner}{objectQualifier}IWebMethods ")
            mySqlString.Append("WHERE PortalID = @PortalID ")
            mySqlString.Append("ORDER BY PortalID, MethodName ")

            Dim prmPortalID As SqlParameter = New SqlParameter("@PortalID", SqlDbType.Int, 4)
            prmPortalID.Value = PorlalID

            Using dr As IDataReader = CType(DotNetNuke.Data.DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), prmPortalID), IDataReader)
                While dr.Read
                    Dim IWEBMethodInfo As New IWEBMethodInfo()
                    IWEBMethodInfo.MethodName = Convert.ToString(dr("MethodName"))
                    IWEBMethodInfo.Portal = Convert.ToString(dr("PortalID"))
                    IWEBMethodInfo.MethodDescription = Convert.ToString(dr("MethodDescription"))
                    IWEBMethodInfo.SecuritySetting = Convert.ToString(dr("SecuritySetting"))
                    IWEBMethodInfo.CompanyName = Convert.ToString(dr("CompanyName"))
                    IWEBMethodInfo.ApplicationName = Convert.ToString(dr("ApplicationName"))
                    IWEBMethodInfo.FirstGrouping = Convert.ToString(dr("FirstGrouping"))
                    IWEBMethodInfo.SecondGrouping = Convert.ToString(dr("SecondGrouping"))
                    IWEBMethodInfoList.Add(IWEBMethodInfo)
                End While
            End Using
            Return IWEBMethodInfoList
        End Function

#End Region

    End Class

End Namespace